widget-factory: Example for edge-overshot
authorMatthias Clasen <mclasen@redhat.com>
Tue, 21 Oct 2014 00:54:31 +0000 (20:54 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 21 Oct 2014 00:54:31 +0000 (20:54 -0400)
For extra fun, make some noise.

configure.ac
demos/widget-factory/Makefile.am
demos/widget-factory/widget-factory.c

index 3ca894275c65cca9f399bddc9827e33bf5105294..d614dde0d7f3ca899f11915a7f652860a990279f 100644 (file)
@@ -1672,6 +1672,16 @@ if test "$have_colord" = "yes"; then
 fi
 AM_CONDITIONAL(HAVE_COLORD, test "x$have_colord" = "xyes")
 
+##################################################
+# Check for libcanberra (only used in examples)
+##################################################
+
+PKG_CHECK_MODULES(LIBCANBERRA, libcanberra-gtk3,
+                  have_libcanberra=yes, have_libcanberra=no)
+if test "$have_libcanberra" = "yes"; then
+        AC_DEFINE(HAVE_LIBCANBERRA, 1, [define if we have libcanberra])
+fi
+
 ##################################################
 # Checks for gtk-doc and docbook-tools
 ##################################################
index d04b9c7e64630e13ef0102128868ecd9897061eb..64902f2bc1bbb3e99ec3164f3b6a00c7e949a5bf 100644 (file)
@@ -18,12 +18,14 @@ gtk3_widget_factory_DEPENDENCIES = \
 gtk3_widget_factory_CPPFLAGS = \
        -I$(top_srcdir)                 \
        $(GTK_DEBUG_FLAGS)              \
-       $(GTK_DEP_CFLAGS)
+       $(GTK_DEP_CFLAGS)               \
+       $(LIBCANBERRA_CFLAGS)
 
 gtk3_widget_factory_LDADD = \
        $(top_builddir)/gdk/libgdk-3.la \
        $(top_builddir)/gtk/libgtk-3.la \
-       $(GTK_DEP_LIBS)
+       $(GTK_DEP_LIBS)                 \
+       $(LIBCANBERRA_LIBS)
 
 widget_factory_resources.c: widget-factory.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/widget-factory.gresource.xml)
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source $<
index 0df81944dc75f21ab9a1f6af64175c9a843898de..a9a36e66be12fb5ef7bf30b3695651276f860987 100644 (file)
  */
 
 #include "config.h"
+
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
+#ifdef HAVE_LIBCANBERRA
+#include <canberra-gtk.h>
+#endif
 
 static void
 change_theme_state (GSimpleAction *action,
@@ -574,6 +578,82 @@ update_title_header (GtkListBoxRow *row,
     }
 }
 
+static void
+overshot (GtkScrolledWindow *sw, GtkPositionType pos, GtkWidget *widget)
+{
+  GtkWidget *box, *row, *label, *swatch;
+  GdkRGBA rgba;
+  const gchar *color;
+  gchar *text;
+  GtkWidget *silver;
+  GtkWidget *gold;
+
+  silver = GTK_WIDGET (g_object_get_data (G_OBJECT (widget), "Silver"));
+  gold = GTK_WIDGET (g_object_get_data (G_OBJECT (widget), "Gold"));
+
+  if (pos == GTK_POS_TOP)
+    {
+      if (silver)
+        {
+          gtk_container_remove (GTK_CONTAINER (widget), silver);
+          g_object_set_data (G_OBJECT (widget), "Silver", NULL);
+        }
+      if (gold)
+        {
+          gtk_container_remove (GTK_CONTAINER (widget), gold);
+          g_object_set_data (G_OBJECT (widget), "Gold", NULL);
+        }
+
+#ifdef HAVE_LIBCANBERRA
+      if (silver || gold)
+        ca_gtk_play_for_widget (widget, 0, "event.id", "message", NULL); 
+#endif
+
+      return;
+    }
+
+
+  if (gold)
+    return;
+  else if (silver)
+    color = "Gold";
+  else
+    color = "Silver";
+
+  row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 20);
+  text = g_strconcat ("<b>", color, "</b>", NULL);
+  label = gtk_label_new (text);
+  g_free (text);
+  g_object_set (label,
+                "use-markup", TRUE,
+                "halign", GTK_ALIGN_START,
+                "valign", GTK_ALIGN_CENTER,
+                "margin", 6,
+                "xalign", 0.0,
+                NULL);
+  gtk_box_pack_start (GTK_BOX (row), label, TRUE, TRUE, 0);
+  gdk_rgba_parse (&rgba, color);
+  swatch = g_object_new (g_type_from_name ("GtkColorSwatch"),
+                         "rgba", &rgba,
+                         "selectable", FALSE,
+                         "halign", GTK_ALIGN_END,
+                         "valign", GTK_ALIGN_CENTER,
+                         "margin", 6,
+                         "height-request", 24,
+                         NULL);
+  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+  gtk_container_add (GTK_CONTAINER (box), swatch);
+  gtk_box_pack_start (GTK_BOX (row), box, FALSE, FALSE, 0);
+  gtk_widget_show_all (row);
+  gtk_list_box_insert (GTK_LIST_BOX (widget), row, -1);
+  row = gtk_widget_get_parent (row);
+  gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
+  g_object_set_data (G_OBJECT (widget), color, row);
+#ifdef HAVE_LIBCANBERRA
+  ca_gtk_play_for_widget (widget, 0, "event.id", "complete", NULL); 
+#endif
+}
+
 static void
 populate_colors (GtkWidget *widget)
 {
@@ -621,6 +701,7 @@ populate_colors (GtkWidget *widget)
   };
   gint i;
   GtkWidget *row, *box, *label, *swatch;
+  GtkWidget *sw;
   GdkRGBA rgba;
 
   gtk_list_box_set_header_func (GTK_LIST_BOX (widget), update_title_header, NULL, NULL);
@@ -657,6 +738,9 @@ populate_colors (GtkWidget *widget)
     }
 
   gtk_list_box_invalidate_headers (GTK_LIST_BOX (widget));
+
+  sw = gtk_widget_get_ancestor (widget, GTK_TYPE_SCROLLED_WINDOW);
+  g_signal_connect (sw, "edge-overshot", G_CALLBACK (overshot), widget);
 }
 
 typedef struct {